<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jsx的babel转换到ReactElement对象到虚拟dom渲染过程</title>
</head>

<body>

  <div id="app"></div>

  <script src="../react/react.development.js"></script>
  <script src="../react/react-dom.development.js"></script>
  <script src="../react/babel.min.js"></script>

  <script type="text/babel">
    // jsx -> createElement函数 -> ReactElement(对象树) -> ReactDOM.render -> 真实DOM
    // jsx -> createElement函数 -> ReactElement(对象树) -> ReactDOM.render -> 原生的控件(UIButton/Button)
    
    // 这是jsx语法
    const msg1 = 
      <div className="header">
        <h2>头部</h2>
        <div className="main">主题</div>
        <footer>这里是尾部</footer>
      </div>; 
    
    // jsx 会转成 React.createElement 函数调用，createElement中会调用 ReactElement函数，然后转成 对象树
    const msg2 = React.createElement("div", {
      class: "header"
    },React.createElement("h2", null, "\u5934\u90E8"), React.createElement("div", {
      class: "main"
    }, "\u4E3B\u9898"), React.createElement("footer", null, "\u8FD9\u91CC\u662F\u5C3E\u90E8"));

    //msg2 就是对象树，也就是虚拟DOM
    console.log(msg2);

    //ReactDOM.render 函数把虚拟DOM 挂载到真实的DOM上
    ReactDOM.render(msg2, document.getElementById("app"));
  </script>


</body>

</html>